// Copyright (C) 2025 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#ifndef ROTHAR_PEGTL_SRC_TEST_PEGTL_VERIFY_META_HPP
#define ROTHAR_PEGTL_SRC_TEST_PEGTL_VERIFY_META_HPP

#include <type_traits>

#include <rothar/pegtl/type_list.hpp>

#include <rothar/pegtl/contrib/analyze.hpp>

#include "test.hpp"

namespace rothar
{
   template< typename Name, typename Rule, typename... Rules >
   void verify_meta()
   {
      static_assert( std::is_same_v< typename Name::rule_t, Rule > );
      static_assert( std::is_same_v< typename Name::subs_t, type_list< Rules... > > );
   }

   template< typename Rule >
   void verify_analyze( const unsigned line, const char* file, const bool expect_consume, const bool expect_problems )
   {
      internal::analyze_cycles< Rule > a( -1 );

      const auto problems = a.problems();

      ROTHAR_PEGTL_TEST_ASSERT( problems == analyze< Rule >( -1 ) );

      const bool has_problems = ( problems != 0 );
      const bool does_consume = a.template consumes< Rule >();

      if( has_problems != expect_problems ) {
         ROTHAR_PEGTL_TEST_FAILED( "analyze -- problems received/expected [ " << has_problems << " / " << expect_problems << " ]" );  // LCOV_EXCL_LINE
      }
      if( does_consume != expect_consume ) {
         ROTHAR_PEGTL_TEST_FAILED( "analyze -- consumes received/expected [ " << does_consume << " / " << expect_consume << " ]" );  // LCOV_EXCL_LINE
      }
   }

}  // namespace rothar

#endif
